<template>
  <div class="row justify-content-center">
    <div class="col-8">
      <form name="editForm" role="form" novalidate v-on:submit.prevent="save()">
        <h2 id="roomAdminApp.cityList.home.createOrEditLabel" data-cy="CityListCreateUpdateHeading">Create or edit a CityList</h2>
        <div>
          <div class="form-group" v-if="cityList.id">
            <label for="id">ID</label>
            <input type="text" class="form-control" id="id" name="id" v-model="cityList.id" readonly />
          </div>
          <div class="form-group">
            <label class="form-control-label" for="city-list-locationId">Location Id</label>
            <input
              type="text"
              class="form-control"
              name="locationId"
              id="city-list-locationId"
              data-cy="locationId"
              :class="{ valid: !$v.cityList.locationId.$invalid, invalid: $v.cityList.locationId.$invalid }"
              v-model="$v.cityList.locationId.$model"
            />
            <div v-if="$v.cityList.locationId.$anyDirty && $v.cityList.locationId.$invalid">
              <small class="form-text text-danger" v-if="!$v.cityList.locationId.maxLength">
                This field cannot be longer than 15 characters.
              </small>
            </div>
          </div>
          <div class="form-group">
            <label class="form-control-label" for="city-list-locationName">Location Name</label>
            <input
              type="text"
              class="form-control"
              name="locationName"
              id="city-list-locationName"
              data-cy="locationName"
              :class="{ valid: !$v.cityList.locationName.$invalid, invalid: $v.cityList.locationName.$invalid }"
              v-model="$v.cityList.locationName.$model"
            />
            <div v-if="$v.cityList.locationName.$anyDirty && $v.cityList.locationName.$invalid">
              <small class="form-text text-danger" v-if="!$v.cityList.locationName.maxLength">
                This field cannot be longer than 20 characters.
              </small>
            </div>
          </div>
          <div class="form-group">
            <label class="form-control-label" for="city-list-countryName">Country Name</label>
            <input
              type="text"
              class="form-control"
              name="countryName"
              id="city-list-countryName"
              data-cy="countryName"
              :class="{ valid: !$v.cityList.countryName.$invalid, invalid: $v.cityList.countryName.$invalid }"
              v-model="$v.cityList.countryName.$model"
            />
            <div v-if="$v.cityList.countryName.$anyDirty && $v.cityList.countryName.$invalid">
              <small class="form-text text-danger" v-if="!$v.cityList.countryName.maxLength">
                This field cannot be longer than 10 characters.
              </small>
            </div>
          </div>
          <div class="form-group">
            <label class="form-control-label" for="city-list-adm1Name">Adm 1 Name</label>
            <input
              type="text"
              class="form-control"
              name="adm1Name"
              id="city-list-adm1Name"
              data-cy="adm1Name"
              :class="{ valid: !$v.cityList.adm1Name.$invalid, invalid: $v.cityList.adm1Name.$invalid }"
              v-model="$v.cityList.adm1Name.$model"
            />
            <div v-if="$v.cityList.adm1Name.$anyDirty && $v.cityList.adm1Name.$invalid">
              <small class="form-text text-danger" v-if="!$v.cityList.adm1Name.maxLength">
                This field cannot be longer than 20 characters.
              </small>
            </div>
          </div>
          <div class="form-group">
            <label class="form-control-label" for="city-list-adm2Name">Adm 2 Name</label>
            <input
              type="text"
              class="form-control"
              name="adm2Name"
              id="city-list-adm2Name"
              data-cy="adm2Name"
              :class="{ valid: !$v.cityList.adm2Name.$invalid, invalid: $v.cityList.adm2Name.$invalid }"
              v-model="$v.cityList.adm2Name.$model"
            />
            <div v-if="$v.cityList.adm2Name.$anyDirty && $v.cityList.adm2Name.$invalid">
              <small class="form-text text-danger" v-if="!$v.cityList.adm2Name.maxLength">
                This field cannot be longer than 20 characters.
              </small>
            </div>
          </div>
          <div class="form-group">
            <label class="form-control-label" for="city-list-latitude">Latitude</label>
            <input
              type="text"
              class="form-control"
              name="latitude"
              id="city-list-latitude"
              data-cy="latitude"
              :class="{ valid: !$v.cityList.latitude.$invalid, invalid: $v.cityList.latitude.$invalid }"
              v-model="$v.cityList.latitude.$model"
            />
            <div v-if="$v.cityList.latitude.$anyDirty && $v.cityList.latitude.$invalid">
              <small class="form-text text-danger" v-if="!$v.cityList.latitude.maxLength">
                This field cannot be longer than 30 characters.
              </small>
            </div>
          </div>
          <div class="form-group">
            <label class="form-control-label" for="city-list-longitude">Longitude</label>
            <input
              type="text"
              class="form-control"
              name="longitude"
              id="city-list-longitude"
              data-cy="longitude"
              :class="{ valid: !$v.cityList.longitude.$invalid, invalid: $v.cityList.longitude.$invalid }"
              v-model="$v.cityList.longitude.$model"
            />
            <div v-if="$v.cityList.longitude.$anyDirty && $v.cityList.longitude.$invalid">
              <small class="form-text text-danger" v-if="!$v.cityList.longitude.maxLength">
                This field cannot be longer than 30 characters.
              </small>
            </div>
          </div>
        </div>
        <div>
          <button type="button" id="cancel-save" data-cy="entityCreateCancelButton" class="btn btn-secondary" v-on:click="previousState()">
            <font-awesome-icon icon="ban"></font-awesome-icon>&nbsp;<span>Cancel</span>
          </button>
          <button
            type="submit"
            id="save-entity"
            data-cy="entityCreateSaveButton"
            :disabled="$v.cityList.$invalid || isSaving"
            class="btn btn-primary"
          >
            <font-awesome-icon icon="save"></font-awesome-icon>&nbsp;<span>Save</span>
          </button>
        </div>
      </form>
    </div>
  </div>
</template>
<script lang="ts" src="./city-list-update.component.ts"></script>
